package com.bops.dal.product.dao.impl;

import java.util.HashMap;
import java.util.List;


import com.bops.dal.product.dao.ProductsDAO;
import com.bops.dal.product.dataobject.ProductsDO;
import com.bops.dal.product.queryobject.ProductsQuery;
import com.yue.commons.db.ibatis.YueBaseSqlMapClientDaoSupport;

public class ProductDAOImpl  extends YueBaseSqlMapClientDaoSupport implements ProductsDAO {
	private static final String NAME_SPACE = "PRODUCTS_INFO.";
	
	
	public int countProduct(HashMap<String, Object> map) {
		return (Integer) getSqlMapClientTemplate().queryForObject(NAME_SPACE + "count_product", map);
	}
	public int checkProduct(ProductsDO editProduct ) {
		return (Integer) getSqlMapClientTemplate().queryForObject(NAME_SPACE + "checkName",  editProduct);
	}

	public int deleteProductById(Integer id) {
		int rows = getSqlMapClientTemplate().delete(NAME_SPACE + "delete", id);
		return rows;
	}

	
	public Integer  insertProduct(ProductsDO record) {
		return (Integer) getSqlMapClientTemplate().insert(NAME_SPACE + "insert", record);
	}

	
	public int updateProduct(ProductsDO record) {
		int rows = getSqlMapClientTemplate().update(NAME_SPACE + "update", record);
		return rows;
	}

	@SuppressWarnings("unchecked")
	public List<ProductsDO> listProduct(ProductsQuery query) {
		if (query==null)
        {
            query = new ProductsQuery();
            query.setPageSize(Integer.MAX_VALUE);
        }
        return getSqlMapClientTemplate().queryForPagination(NAME_SPACE + "count_product",
        		NAME_SPACE + "list_product", query);
	}
	
	@SuppressWarnings("unchecked")
	public List<ProductsDO> completeProduct(ProductsQuery query) {
		return getSqlMapClientTemplate().queryForList(NAME_SPACE + "complete_products", query);
	}

	
	public ProductsDO findProductById(Integer id) {
		return (ProductsDO)getSqlMapClientTemplate().queryForObject(NAME_SPACE + "listById", id);
	}
	public ProductsDO findProductIDByName(ProductsQuery query) {
		return (ProductsDO)getSqlMapClientTemplate().queryForObject(NAME_SPACE + "productsIdByName", query);
	}
	
	public ProductsDO findProduct_cloud_ById(Integer id) {
		return (ProductsDO)getSqlMapClientTemplate().queryForObject(NAME_SPACE + "listById_cloud", id);
	}
    
}